# -*- coding: utf-8 -*-

"""Unimail
@version: 0.14
@license: GPL 3.0 (see "license" file)
@author: Jose A. Jimenez
@contact: jajimc@gmail.com"""

import os
import configuration

DATA_DIR = os.path.join(os.path.expanduser("~"), ".unimail")
CONFIG_DIR = os.path.join(DATA_DIR, "config")
SETTINGS_FILE = os.path.join(CONFIG_DIR, "account-settings")
TEMP_DIR = os.path.join(DATA_DIR, "temp")
INPUT_TEMP_DIR = os.path.join(TEMP_DIR, "input")
OUTPUT_TEMP_DIR = os.path.join(TEMP_DIR, "output")
DEFAULT_INBOX_DIR = os.path.join(os.path.expanduser("~"), "Unimail Inbox")

def check_paths():
    """Checks if all paths exist and if not, creates them."""
    if not (os.path.isdir(DATA_DIR) and not os.path.islink(DATA_DIR)):
        os.mkdir(DATA_DIR)
        
    if not (os.path.isdir(CONFIG_DIR) and not os.path.islink(CONFIG_DIR)):
        os.mkdir(CONFIG_DIR)

    if not (os.path.isfile(SETTINGS_FILE) and not os.path.islink(SETTINGS_FILE)):
        settings = configuration.get_default_settings()
        configuration.save_settings(settings)
        
    if not (os.path.isdir(TEMP_DIR) and not os.path.islink(TEMP_DIR)):
        os.mkdir(TEMP_DIR)
        
    if not (os.path.isdir(INPUT_TEMP_DIR) and not os.path.islink(INPUT_TEMP_DIR)):
        os.mkdir(INPUT_TEMP_DIR)
        
    if not (os.path.isdir(OUTPUT_TEMP_DIR) and not os.path.islink(OUTPUT_TEMP_DIR)):
        os.mkdir(OUTPUT_TEMP_DIR)

    settings = configuration.load_settings()
    inboxDirPath = settings.get_inbox_dir_path()
    if inboxDirPath != "" and not os.path.isfile(inboxDirPath) and not os.path.isdir(inboxDirPath) and not os.path.islink(inboxDirPath):
        os.mkdir(inboxDirPath)
